package cn.leedsoft.luma.test.design_pattern;

/**
 * 模版方法模式
 * Created by leeds on 2017/6/14.
 * 1、一个抽象类，若干个实现类
 * 2、抽象类由模板方法和抽象方法构成。模板方法即通用方法。
 */
public class TemplateMethod {
    public static void main(String[] args) {
        System.out.println("------奔驰车模板----------");
        Model benz = new BenzModel();
        benz.run();
        System.out.println("------宝马车模板----------");
        Model bmw = new BMWModel();
        bmw.run();
    }
}

abstract class Model {
    //车辆启动
    protected abstract void start();//抽象方法

    //车辆停止
    protected abstract void stop();

    //车辆鸣笛
    protected abstract void alarm();

    //车辆发动机轰鸣
    protected abstract void engineBoom();

    protected void run() {//模板方法
        this.engineBoom();
        this.start();
        this.alarm();
        this.stop();
    }
}

class BMWModel extends Model {
    @Override
    protected void start() {
        System.out.println("宝马车启动...");
    }

    @Override
    protected void stop() {
        System.out.println("宝马车停止...");
    }

    @Override
    protected void alarm() {
        System.out.println("宝马车开始鸣笛...");
    }

    @Override
    protected void engineBoom() {
        System.out.println("宝马车发动机轰鸣...");
    }
}

class BenzModel extends Model {
    @Override
    protected void start() {
        System.out.println("奔驰启动...");
    }

    @Override
    protected void stop() {
        System.out.println("奔驰停止...");
    }

    @Override
    protected void alarm() {
        System.out.println("奔驰开始鸣笛...");
    }

    @Override
    protected void engineBoom() {
        System.out.println("奔驰发动机轰鸣...");
    }
}
